package com.sn.seabattle;

import java.io.Serializable;
import java.util.List;

public class Ship implements Serializable {
    private int hp;
    private int size;
    private List<Cell> cells;

    public Ship(List<Cell> list) {
        cells = list;
        hp = cells.size();
        size=hp;
        for (int i = 0; i < hp; i++) {
            cells.get(i).setShip(this);
        }
    }

    public int attack(Cell[][] area) {
        if (this.hp == 1) {
            for (Cell l : cells) {
                l.borderH(area);
            }
            return 2;
        } else {            
            this.hp--;
            return 1;
        }
    }

    public int getHp() {
        return hp;
    }
    public int getSize() {
        return size;
    }

    public void dell(Cell[][] area) {
        for (Cell l : cells) {
            l.deborder(area);
            l.setValue(0);
            l.setShip(null);
        }
    }

    public void border(Cell[][] area) {
        for (Cell l : cells) {
            if (l.getValue() == 2) {
                l.border(area);
            }
        }
        
    }
    public void deborder(Cell[][] area) {
        for (Cell l : cells) {
            l.deborder(area);
        }
        
    }

}
